// Copyright 2023 Leo <lipf160627@163.com>. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.

package model

import (
	"time"

	"gorm.io/gorm"

	"gitee.com/lrobin/dl-lab/model/address"
	"github.com/go-playground/validator/v10"
)

type UserRole int

const (
	Unregister UserRole = iota
	Common
	Vip
	Admin
)

type UserAddress struct {
	gorm.Model
	Province address.Province `json:"province" gorm:"comment:省"`
	City     string           `json:"city" gorm:"comment:市"`
}

type User struct {
	gorm.Model
	// Username string      `json:"username" gorm:"comment:用户登录名" validate:"required,min=6,max=16"`
	Email     string      `json:"email" gorm:"comment:用户邮箱" validate:"required,email"`
	NickName  string      `json:"nickName" gorm:"default:追梦小喵;comment:用户昵称"`
	Password  string      `json:"password" gorm:"comment:用户登录密码" validate:"required,min=6,max=16"`
	Address   UserAddress `json:"address" gorm:"comment:用户地址;foreignkey:ID;references:id"`
	Role      UserRole    `json:"role" gorm:"comment:用户角色"`
	Credits   int         `json:"credits" gorm:"comment:用户积分" validate:"gte=0"`
	Birthday  time.Time   `json:"birthday" gorm:"comment:用户生日;type=date" validate:"required"`
	Telephone string      `json:"telephone" gorm:"comment:用户手机号"`
	// UUID        uuid.UUID `json:"uuid" gorm:"comment:用户UUID"`                                                           // 用户UUID
	// SideMode    string    `json:"sideMode" gorm:"default:dark;comment:用户侧边主题"`                                          // 用户侧边主题
	// HeaderImg   string    `json:"headerImg" gorm:"default:https://qmplusimg.henrongyi.top/gva_header.jpg;comment:用户头像"` // 用户头像
	// BaseColor   string    `json:"baseColor" gorm:"default:#fff;comment:基础颜色" validate:"iscolor"`                                           // 基础颜色
	// ActiveColor string    `json:"activeColor" gorm:"default:#1890ff;comment:活跃颜色" validate:"iscolor"`                                      // 活跃颜色
	// AuthorityId string    `json:"authorityId" gorm:"default:888;comment:用户角色ID"`                                        // 用户角色ID
	// Authority   SysAuthority   `json:"authority" gorm:"foreignKey:AuthorityId;references:AuthorityId;comment:用户角色"`
	// Authorities []SysAuthority `json:"authorities" gorm:"many2many:sys_user_authority;"`
}

func (u *User) Validate(v *validator.Validate) error {
	return v.Struct(u)
}
